Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation of the ability to change the base color #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

KevinRohn
Copy link

@KevinRohn KevinRohn commented Jan 10, 2021

I've implemented the ability to change the base color of the model.

There is a ModelViewerColorController which can be used to call the JavaScript function to change the base color of the model.
Currently it only supports the auto detected base color. As I understand the documentation, the auto detection selects the largest area of the model. So if there is just a simple model, you can change the color of the whole object. Otherwise the largest object will just be changed.

Example usage:

// ....
ModelViewerColorController _colorController;

// ....
@override
void initState() {
    super.initState();
    _colorController = ModelViewerColorController();
}

// ....
Future void changeColor() async {
    await _colorController.changeColor("0,1,1,1");
}

// ....
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("Model Viewer")),
        body: ModelViewer(
          src: 'https://modelviewer.dev/shared-assets/models/Astronaut.glb',
          enableColorChange: true,
          colorController: _colorController,
          alt: "A 3D model of an astronaut",
          ar: true,
          autoRotate: true,
          cameraControls: true,
        ),
      ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant